package com.ztf.reflection.study;

import java.lang.reflect.Method;

public class InvokeTester {
    public int add(int param1,int param2){
        return param1+param2;

    }

    public String echo(String param1){
        return  param1;
    }

    public static void main(String[] args) throws Exception {
//        InvokeTester invokeTester = new InvokeTester();
//        int y = invokeTester.add(1,2);
//        System.out.println(y);
        Class classType = InvokeTester.class;
        Object invokeTester = classType.newInstance();
        System.out.println(invokeTester instanceof InvokeTester);
        Method method = classType.getMethod("add",new Class[]{int.class,int.class});
        Object result = method.invoke(invokeTester,new Object[]{1,2});
        System.out.println("======="+result);
        Method method1 = classType.getMethod("echo", new Class[]{String.class});
        Object result2 = method1.invoke(invokeTester,new Object[]{"tom"});
        System.out.println("======"+result2);
    }
}
